/*-------- 追加写入 -------- */

let fs = require('fs');
let temp = '';
let wrap = '这是要追加写入的内容';

let read = fs.createReadStream('./data/source.txt');
read.setEncoding('UTF8');

read.on('data', function (content) {
	console.log('正在读取数据!');
	temp = content;
})

read.on('end', function () {
	console.log('数据读取完毕!');
	// ...

	temp += wrap;

	let write = fs.createWriteStream('./data/output.txt');
	write.write(temp, 'UTF8');
	write.end();

	write.on('finish', function () {
		console.log('数据写入完成!');
	})

	write.on('error', function () {
		console.log('出错信息', err.stack);
	})

})

read.on('error', function () {
	console.log('出错信息: ', err.stack);
})

console.log('文件管道流.js执行完毕!');
